// 用户管理接口文档
import { api } from 'boot/axios'

/** 新增用户数：
 * name	String	是	用户姓名
 * phoneNumber	String	是	联系电话
 * isManage	String	是	是否为管理员（如是、否）
 **/
export interface IUserParam {
  name: string
  phoneNumber: string
  isManage: string
}
export interface IEditUserParam extends IUserParam {
  userId: number
}

const USER_URL = '/house/user'
const USER_PAGE_URL = '/house/user/page'
const USER_LIST_URL = '/house/user/list'

// User
export function addUser(data: IUserParam) {
  return api.post(USER_URL, data)
}
export function editUser(data: IEditUserParam) {
  return api.put(USER_URL, data)
}
export function editUserRole(data: { userId: number; role: string }) {
  return api.put(`${USER_URL}/role`, data)
}
export function removeUser(id: number) {
  return api.delete(`${USER_URL}/${id}`)
}
export function getUserById(id: number) {
  return api.get(`${USER_URL}/${id}`)
}
export function getUserList() {
  return api.get(USER_LIST_URL)
}
export interface IUserQueryParams {
  pageNum: number
  pageSize: number
  name?: string
}
export function getUserPageList(
  { pageNum = 1, pageSize = 10, name }: IUserQueryParams = { pageNum: 1, pageSize: 10, name: '' }
) {
  const params: IUserQueryParams = { pageNum, pageSize }
  if (name) {
    params.name = name
  }
  return api.get(USER_PAGE_URL, { params })
}
